package com.zp.self.module.工具.json转换.json_json;

import com.zp.self.module.工具.json转换.jsonUtil.JsonUtil;
import org.json.JSONArray;
import org.json.JSONObject;

import java.io.IOException;

/**
 * @author ：by peng.zeng
 * @date ：Created 2021/9/3 15:05
 * @description ：整理
 */
public class Json2CsvOk_多文件多列 {
    public static void main(String[] args) throws IOException {
        JSONArray mainJson = JsonUtil.getJson("C:\\Users\\peng.zeng\\Desktop\\设备info_2021.json");
        JSONArray otherJson_0 = JsonUtil.getJson("C:\\Users\\peng.zeng\\Desktop\\support2021.json");
        JSONArray otherJson_1 = JsonUtil.getJson("C:\\Users\\peng.zeng\\Desktop\\report_2021.json");

        JsonUtil.multipleJsonMerge(mainJson, otherJson_0, "deviceId","support S (%)","support LF (%)","support RF (%)"
        ,"support untitled (%)");
        JsonUtil.multipleJsonMerge(mainJson, otherJson_1, "deviceId","Ouput (m?/h)"
                ,"fuel consumption while pumping (l/h)","fuel consumption while washing (l/h)"
                ,"fuel consumption while idle (l/h)","fuel consumption while Setup (l/h)"
                ,"fuel consumption while driving (l/h)","fuel consumption while driving (l/100km)",
                "fuel consumption per pumped concrete (l/m?) "
        ,"driven distance (km)","CO2 emissions (kg)");
        JSONObject jo = mainJson.getJSONObject(0);
        if(jo.get("Ouput (m?/h)")==null){
            jo.put("Ouput (m?/h)",0);
        }
        JsonUtil.json2csv(mainJson,"C:\\Users\\peng.zeng\\Desktop\\2021_report.csv");
    }
}
